package models

import (
	"gorm.io/gorm/schema"
)

type RbacRole struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields

	Domain   string `json:"domain" gorm:"type:varchar(10)"` //所在域（命名空间）
	Name     string `json:"name" gorm:"type:varchar(32)"`
	Describe string `json:"describe" gorm:"type:varchar(128)"`
	Sort     int    `json:"sort" gorm:"type:int"`

	Status int `json:"status" gorm:"type:tinyint"` //0:未知，1：可用，2：禁用
}

func (r *RbacRole) TableName(namer schema.Namer) string {
	return namer.TableName("rbac_role")
}

type RbacUserRole struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields

	UserId int64 `json:"user_id" gorm:"index"`
	RoleId int64 `json:"role_id" gorm:"index"`
}

func (r *RbacUserRole) TableName(namer schema.Namer) string {
	return namer.TableName("rbac_user_role")
}

type RbacRolePermission struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields

	RoleId       int64 `json:"role_id" gorm:"index"`
	PermissionId int64 `json:"permission_id" gorm:"index"`
}

func (r *RbacRolePermission) TableName(namer schema.Namer) string {
	return namer.TableName("rbac_role_perms")
}

type RbacPermission struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields

	Name     string `json:"name" gorm:"type:varchar(64)"`
	Describe string `json:"describe" gorm:"type:varchar(128)"`
	Path     string `json:"path" gorm:"type:varchar(256)"` //对应权限路径：页面路径/api路径
	Type     string `json:"type" gorm:"type:varchar(16)"`  //类型, 枚举： menu/action/api，可参考下面的 PermissionType前缀的常量
	Icon     string `json:"icon" gorm:"type:varchar(256)"`
	Sort     int    `json:"sort" gorm:"type:int"`
	Pid      int64  `json:"pid" gorm:"index"`
	Remark   string `json:"remark" gorm:"type:varchar(512)"`
	Status   int    `json:"status" gorm:"type:tinyint"`

	Paths []string `json:"paths" gorm:"-"` //对应的权限路径集合
}

func (r *RbacPermission) TableName(namer schema.Namer) string {
	return namer.TableName("rbac_perms")
}
